package com.google.smartbinding.framework.swt.demo.view;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

import com.google.smartbinding.framework.swt.demo.view.model.DemoCompositeModel;
import com.googlecode.smartbinding.framework.core.Bindable;
import com.googlecode.smartbinding.framework.core.Binding;

@Bindable(source=DemoCompositeModel.class)
public class DemoComposite extends Composite {
	
	@Binding(property="name")
	private Text textName;
	
	@Binding(property="weight")
	private Text textWeight;
	
	private TableViewer tableViewer;
	private Button btnAdd;

	public DemoComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(1, false));		
		init();
	}

	private void init() {
		Group groupInput = new Group(this, SWT.NONE);
		groupInput.setText("Input");
		groupInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		groupInput.setLayout(new GridLayout(2, false));
		
		Label lblName = new Label(groupInput, SWT.NONE);
		lblName.setSize(31, 13);
		lblName.setText("Name:");
		
		textName = new Text(groupInput, SWT.BORDER);
		textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textName.setSize(397, 19);
		
		Label lblWeight = new Label(groupInput, SWT.NONE);
		lblWeight.setSize(38, 13);
		lblWeight.setText("Weight:");
		
		textWeight = new Text(groupInput, SWT.BORDER);
		textWeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textWeight.setSize(397, 19);
		new Label(groupInput, SWT.NONE);
		
		btnAdd = new Button(groupInput, SWT.NONE);
		btnAdd.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		btnAdd.setText("Add");
		
		Group grpList = new Group(this, SWT.NONE);
		grpList.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		grpList.setText("List:");
		
		tableViewer = new TableViewer(grpList, SWT.BORDER | SWT.FULL_SELECTION);
		Table tableResult = tableViewer.getTable();
		tableResult.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
	}

	public Text getTextName() {
		return textName;
	}

	public Text getTextWeight() {
		return textWeight;
	}

	public TableViewer getTableViewer() {
		return tableViewer;
	}

	public Button getBtnAdd() {
		return btnAdd;
	}
	
	
}
